<template>
  <!-- 新增挂号弹窗 -->
  <el-dialog title="新增挂号" :visible.sync="visible" width="400px" @close="close">
    <!-- 挂号表单区域 -->
    <el-form :model="form" label-width="80px">
      <el-form-item label="姓名">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="form.gender" placeholder="请选择">
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="form.idCard" />
      </el-form-item>
      <el-form-item label="出生日期">
        <el-date-picker v-model="form.birthDate" type="date" placeholder="选择日期" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.phone" />
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="form.address" />
      </el-form-item>
    </el-form>
    <!-- 弹窗底部按钮区域 -->
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="register">确定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, watch } from 'vue'
// 接收父组件传递的visible属性
const props = defineProps({ visible: Boolean })
// 定义事件emit
const emit = defineEmits(['close', 'register'])

// 挂号表单数据
const form = ref({
  name: '',
  gender: '',
  idCard: '',
  birthDate: '',
  phone: '',
  address: ''
})

// 控制弹窗显示/隐藏
const visible = ref(true)
// 监听父组件visible变化
watch(() => props.visible, v => visible.value = v)

// 关闭弹窗
function close() {
  emit('close')
  // 关闭时清空表单
  form.value = { name: '', gender: '', idCard: '', birthDate: '', phone: '', address: '' }
}
// 提交挂号
function register() {
  emit('register', { ...form.value })
  close()
}
</script> 